import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
///自定义弹窗
class CustomAlertDialog extends Dialog {
  ///标题
  String? title = "";

  ///标题
  String? content = "";

  ///取消
  String? cancelStr = "取消";

  ///确定
  String? sureStr = "确定";

  /// 顶部图标
  Widget? icon;

  ///点击取消
  late GestureTapCallback? onCancel;

  ///点击确定
  late GestureTapCallback? onSure;

  ///构造函数
  CustomAlertDialog(
      {Key? key,
        this.title,
        this.content,
        this.cancelStr,
        this.sureStr,
        this.onCancel,
        this.onSure,
        this.icon})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Center(
        child: IntrinsicHeight(
          child: Container(
            margin: const EdgeInsets.only(left: 38, right: 38),
            padding: EdgeInsets.symmetric(vertical: 48.h, horizontal: 60.w),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(12),
            ),
            child: Column(
              children: [
                icon ?? Container(),
                Text(
                  title ?? "",
                  textAlign: TextAlign.center,
                  style: TextStyle(
                      color: const Color(0xFF1F1F1F),
                      fontSize: 32.sp,
                      fontWeight: FontWeight.bold),
                ),
                SizedBox(height: 30.h),
                Visibility(
                    visible: content?.isNotEmpty == true,
                    child: Column(
                      children: [
                        Text(
                          content ?? "",
                          textAlign: TextAlign.left,
                          style: TextStyle(
                              letterSpacing: -1,
                              color: const Color(0xFF666666),
                              fontSize: 28.sp,
                              fontWeight: FontWeight.bold),
                        ),
                        SizedBox(height: 48.h),
                      ],
                    )),
                Visibility(
                  visible: content?.isNotEmpty != true,
                  child: SizedBox(height: 20.h),
                ),
                Row(
                  children: [
                    Visibility(
                      visible: onCancel != null,
                      child: Expanded(
                        child: GestureDetector(
                          onTap: onCancel,
                          child: Container(
                            alignment: Alignment.center,
                            height: 72.h,
                            decoration: BoxDecoration(
                              color: const Color(0xffF1F1F1),
                              borderRadius: BorderRadius.circular(30),
                            ),
                            child: Text(
                              cancelStr ?? "",
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                color: const Color(0xFF1F1F1F),
                                fontSize: 26.sp,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    Visibility(
                      visible: onCancel != null && onSure != null,
                      child: SizedBox(width: 32.w),
                    ),
                    Visibility(
                      visible: onSure != null,
                      child: Expanded(
                        child: GestureDetector(
                          onTap: onSure,
                          child: Container(
                            alignment: Alignment.center,
                            height: 72.h,
                            decoration: BoxDecoration(
                              color: const Color(0xFFED5130),
                              borderRadius: BorderRadius.circular(30.w),
                            ),
                            child: Text(
                              sureStr ?? "",
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                color: const Color(0xffffffff),
                                fontSize: 36.sp,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}